﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.Collections.Generic;
using System.Drawing.Drawing2D;

namespace smallDeimos
{
    public class MapDrawer
    {
        public static int Width = 600;
        public static int Height = 600;
        public static Bitmap DrawMap(int sId, int bio)
        {
            Bitmap bmp = new Bitmap(Width, Height);
            Graphics grp = Graphics.FromImage(bmp);
            grp.FillRectangle(new SolidBrush(Color.Black), 0, 0, bmp.Width, bmp.Height);
            List<int> cords = UserDefinedFunctions.SystemCoordinates(sId);
            int x = cords[0], y = cords[1];
            List<int[]> systems = UserDefinedFunctions.GetAllSystemsFromBioRange(sId, bio);
            //divide the picture to the grid of bio x bio dimensions. Each cell may contain system.
            int cellW, cellH;
            cellW = bmp.Width / bio;
            cellH = bmp.Height / bio;
            Font f = new Font(FontFamily.GenericSerif, 10);
            for (int i = 0; i < bio; i++)
            {
                grp.DrawString((-bio / 2 + i ).ToString(), f, new SolidBrush(Color.White), (2 * i + 1) * cellW / 2, 2);
                grp.DrawString((-bio / 2 + i ).ToString(), f, new SolidBrush(Color.White), 2, (2 * i + 1) * cellH / 2);

                grp.DrawLine(Pens.DarkGray , 0, i * cellH, bmp.Width, i * cellH);
                grp.DrawLine(Pens.DarkGray , i * cellW, 0, i * cellW, bmp.Height);
            }

            grp.TranslateTransform(cellW * bio / 2, cellH * bio / 2);
            LinearGradientBrush lg = new LinearGradientBrush(new Point(0, 0), new Point(20, 20), Color.Blue, Color.BlueViolet);
            foreach (int[] t in systems)
            {
                //float p = cellH / 2;
                //float x = (cellW * t[0] - p) / 2;
                //float y = (cellH * t[1] - p) / 2;
                grp.FillEllipse(lg, cellW * t[0], cellH * t[1], Math.Min(20, cellW / 2), Math.Min(20, cellH / 2));
            }
            return bmp;
        }
    }
}